package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:借阅书籍
 * User: 86184
 * Date: 2023-02-18
 * Time: 15:19
 */
public class BorrowOperation implements IOperation{
    public void work(BookList bookList){
        System.out.println("请输入你要借阅的书籍得到书名!");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();

        int currentSize = bookList.getUseSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getPos(i);
            if (name.equals(book.getName())) {
                if(book.isBorrowed()){
                    System.out.println("该书已借出");
                    return;
                }else {
                    book.setBorrowed(true);
                    System.out.println("借阅图书成功");
                    return;
                }
            }
        }
        System.out.println("没有找到你要借阅的书");
    }
}
